/**
 * ****************************************************************************
 * Project: RoboBridge
 * ----------------------------------------------------------------------------
 * -------------------------- [c]2012 - KrawallMann ---------------------------
 * ---------------------- http://www.krawallmann.de.tc/ -----------------------
 * ****************************************************************************
 * File: Stopwatch.java Package: tc.de.krawallmann.robobridge Version: 1.0
 * Author(s): KrawallMann
 * ****************************************************************************
 * Description:
 * ****************************************************************************
 */
package tc.de.krawallmann.robobridge;

/**
 * The Class Stopwatch is used for timing.
 * 
 * @author KrawallMann
 * @version 1.0
 */
public class Stopwatch {

	/** The running. */
	private transient boolean running = false;

	/** The started. */
	private transient long started = 0;

	/** The stopped. */
	private transient long stopped = 0;

	/**
	 * Gets the ms.
	 * 
	 * @return the ms
	 */
	public long getMS() {
		long elapsed;
		if (running) {
			elapsed = System.currentTimeMillis() - started;
		} else {
			elapsed = stopped - started;
		}
		return elapsed;
	}

	/**
	 * Checks if is running.
	 * 
	 * @return true, if is running
	 */
	public boolean isRunning() {
		return running;
	}

	/**
	 * Reset.
	 */
	public void reset() {
		started = System.currentTimeMillis();
		stopped = 0;
	}

	/**
	 * Start.
	 */
	public void start() {
		started = System.currentTimeMillis();
		running = true;
	}

	/**
	 * Stop.
	 */
	public void stop() {
		stopped = System.currentTimeMillis();
		running = false;
	}
}
